package com.example.front.arrange;

/**
 * Plugin
 *
 * @author liming2
 * @date 2023/11/1 11:55
 */
public abstract class Plugin<R> {

    private R result;

    final public void doHandle(Plugin<?>... plugins) {
        if (result == null) {
            this.result = this.handle(plugins);
        }
    }

    abstract R handle(Plugin<?>... plugins);

    final public R getResult() {
        return result;
    }

    final public void setResult(R result) {
        this.result = result;
    }

    public String getName() {
        return this.getClass().getName();
    }

    public static <R> R getParam(Class<R> tClass, AbstractTask<?>... plugins) {
        for (AbstractTask<?> plugin : plugins) {
            if (plugin.getResult().getClass() == tClass) {
                return (R) plugin.getResult();
            }
        }
        return null;
    }
}
